<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/5/6 0006
 * Time: 下午 2:53
 */

namespace app\admin\controller;

use app\index\model\IntegralUsed;
use think\Db;
use think\Request;

class Integral extends Common
{
    /**
     * @title   积分提现列表
     * @return mixed
     */
    public function index()
    {
        if(Request::instance()->isGet()) {
            $type = input('get.type');
            $key = input('get.key');
            $value = input('get.value');
            switch ($key) {
                case 'bank_username':
                    $where['iu.state'] = $type;
                    $where['u.bank_username'] = array('like',"%".$value."%");
                    break;
                case 'u_username':
                    $where['iu.state'] = $type;
                    $where['u.u_username'] = array('like',"%".$value."%");
                    break;
            }
        }
        $where['iu.iu_status'] = 1;
        $where['iu.iu_mean'] = 2;
        $select = Db::name('integral_used')->alias('iu')->where($where)
            ->field('iu.id as id,createtime,msg,state,iu_type,iu_status,iu_integral,iu_mean,u_username,u_nickname,bank_number,bank_username,bank_name')
            ->join('__USER__ u','iu.iu_uid=u.id','left')
            ->order('createtime desc')
            ->select();
        $this->assign('list',$select);
//        dump($select);die;
        return $this->fetch('admin/Integral/index');
    }

    /**
     * @title   提现完成操作
     * @param null $id
     */
    public function ok(&$id=null)
    {
        $set_state = (new IntegralUsed())->where('id',$id)->setField('state',1);
        if($set_state)     $this->success('完成提现操作');
        else               $this->error('操作失败');
    }

    /**
     * @title   备注信息
     * @param null $id
     */
    public function msg(&$id = null)
    {
        $set_msg = (new IntegralUsed())->where('id',$id)->setField('msg',input('get.msg'));
        if($set_msg)    $this->success('备注完成');
        else            $this->error('备注失败');
    }
}